package com.example.basemvvmkotlin.ui

import android.os.Bundle
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.basemvvmkotlin.R
import com.example.basemvvmkotlin.databinding.ActicityRvBinding
import com.example.basemvvmkotlin.net.DataList
import com.example.basemvvmkotlin.vm.NewsListVm
import com.example.lib_base.base.activity.BaseRVActivity
import com.example.lib_base.base.adapter.LoadMoreAdapter
import com.zy.multistatepage.MultiStateContainer

class TestRvActivity: BaseRVActivity<ActicityRvBinding, NewsListVm, DataList>() {



//    override fun createAdapter(): BaseQuickAdapter<DataList, BaseViewHolder> {
//      return object :BaseQuickAdapter<DataList, BaseViewHolder>(R.layout.item_news){
//          override fun convert(holder: BaseViewHolder, item: DataList) {
//              holder.setText(R.id.title,item.title)
//          }
//      }
//    }

    override fun createAdapter(): BaseQuickAdapter<DataList, BaseViewHolder> {
      return object : LoadMoreAdapter<DataList, BaseViewHolder>(R.layout.item_news){
          override fun convert(holder: BaseViewHolder, item: DataList) {
              holder.setText(R.id.title,item.title)
          }

      }
    }

    override fun createClass(): Class<*> {
       return DataList::class.java
    }

    override fun createViewModel(): NewsListVm {
      return NewsListVm()
    }

    override fun getLayoutId(): Int {
       return R.layout.acticity_rv
    }


    override fun initialize(savedInstanceState: Bundle?) {
        super.initialize(savedInstanceState)
        initRecyclerView()

        binding.btn.setOnClickListener {
            page = 1
            viewModel.getNewsListBean(page)
        }
        binding.btn2.setOnClickListener {
            onLoadMore()
        }

    }

//    override fun onLoadMores() {
//        super.onLoadMores()
//        page += 1
//        viewModel.getNewsListBean(page)
//    }

    override fun onLoadMore() {
        super.onLoadMore()
    }

    override fun createListData(page: Int) {
       viewModel.getNewsListBean(page)
    }


}